// JavaScript Document
function timestamp(){
    setInterval("jQuery('#now_timestamp').text(Math.round(new Date().getTime()/1000));",1000);
    function timestamptostr(timestamp) {
         d = new Date(timestamp * 1000);
         var jstimestamp = (d.getFullYear())+"-"+(d.getMonth()+1)+"-"+(d.getDate())+" "+(d.getHours())+":"+(d.getMinutes())+":"+(d.getSeconds());
         return jstimestamp;
    }
    jQuery('#unixtime').val(Math.round(new Date().getTime() / 1000));

    jQuery('#toGMT').click(function () {
        jQuery('#result_GMT').val(timestamptostr(jQuery('#unixtime').val()));
    })
    
    var now_strTime = timestamptostr(Math.round(new Date().getTime()/1000));
    var arr = new Array();
    arr = now_strTime.split(' ');
    YMD = arr[0].split('-');
    HIS = arr[1].split(':');
    jQuery('#year').val(YMD[0]);
    jQuery('#month').val(YMD[1]);
    jQuery('#day').val(YMD[2]);
    jQuery('#hour').val(HIS[0]);
    jQuery('#minute').val(HIS[1]);
    jQuery('#second').val(HIS[2]);

    jQuery('#toUNIX').click(function () {
        var utime = new Date(Date.UTC(jQuery('#year').val(), jQuery('#month').val() - 1, jQuery('#day').val(), jQuery('#hour').val() - 8, jQuery('#minute').val(), jQuery('#second').val()));
        jQuery('#result_unix').val(utime.getTime() / 1000);
    })
}

jQuery(function () {
    timestamp();
})